﻿namespace Sidvall.Net
{
    public static class AuthenticationHeaderManager
    {
        #region Public Members

        public static AuthenticationHeader NewBasicHeader(string userName, string password)
        {
            return new AuthenticationHeader()
            {
                Scheme = "Basic",
                Parameter = EncodeCredential(userName, password),
            };
        }
        public static AuthenticationHeader NewBearerHeader(string token)
        {
            return new AuthenticationHeader()
            {
                Scheme = "Bearer",
                Parameter = token,
            };
        }

        #endregion
        #region Private Members

        #region EncodeCredential

        private static string EncodeCredential(string userName, string password)
        {
            string credential = System.String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}", userName, password);
            return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(credential));
        }

        #endregion

        #endregion
    }
}
